using System;

namespace System.Web.Core
{
    public class RequestHelper
    {
        public static BaseRequestBinder BuildDeleteUserRoleRequest(int userId, int roleId)
        {
            UserRoleRequest request = new UserRoleRequest();
            request.CommandIdent = CommandIdent.RemoveUserFromRole;
            request.UserId = userId;
            request.RoleId = roleId;

            BaseRequestBinder binder = new TBaseRequestBinder<UserRoleReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildDeleteUserRolesRequest(int userId)
        {
            UserRoleRequest request = new UserRoleRequest();
            request.CommandIdent = CommandIdent.RemoveUserRoles;
            request.UserId = userId;

            BaseRequestBinder binder = new TBaseRequestBinder<UserRoleReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildCreateUserRoleRequest(int userId, int roleId)
        {
            UserRole userRole = new UserRole();
            userRole.UserId.Value = userId;
            userRole.RoleId.Value = roleId;

            BaseRequestBinder binder = new TBaseRequestBinder<UserRoleReply, AddOperation>
            (
                RequestBuilder.BuildAddEntityRequest<UserRoleRequest>(userRole)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetUserRoleRequest(int userId, int roleId)
        {
            UserRoleListRequest request = new UserRoleListRequest();
            request.UserId = userId;
            request.RoleId = roleId;

            BaseRequestBinder binder = new TBaseRequestBinder<UserRoleReply, GetListOperation>
            (
                RequestBuilder.BuildGetEntityListRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetUserRolesRequest(int userId)
        {
            RoleListRequest request = new RoleListRequest();
            request.CommandIdent = CommandIdent.GetUserRoles;
            request.UserId = userId;

            BaseRequestBinder binder = new TBaseRequestBinder<RoleReply, GetListOperation>
            (
                RequestBuilder.BuildGetEntityListRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetRoleUsersRequest(int roleId)
        {
            UserListRequest request = new UserListRequest();
            request.CommandIdent = CommandIdent.GetRoleUsers;
            request.RoleId = roleId;

            BaseRequestBinder binder = new TBaseRequestBinder<UserReply, GetListOperation>
            (
                RequestBuilder.BuildGetEntityListRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetAllRolesRequest()
        {
            RoleListRequest request = new RoleListRequest();
            request.PageSize = 10000;
            BaseRequestBinder binder = new TBaseRequestBinder<RoleReply, GetListOperation>
            (
                RequestBuilder.BuildGetEntityListRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetRoleRequest(int roleId)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<RoleReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest<RoleRequest>(roleId)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetRoleRequest(string name)
        {
            RoleRequest request = new RoleRequest();
            request.CommandIdent = CommandIdent.GetRole;
            request.Name = name;

            BaseRequestBinder binder = new TBaseRequestBinder<RoleReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildCreateRoleRequest(Role role)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<RoleReply, AddOperation>
            (
                RequestBuilder.BuildAddEntityRequest<RoleRequest>(role)
            );
            return binder;
        }
        public static BaseRequestBinder BuildUpdateRoleRequest(Role role)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<RoleReply, GetOperation>
            (
                RequestBuilder.BuildUpdateEntityRequest<RoleRequest>(role)
            );
            return binder;
        }
        public static BaseRequestBinder BuildDeleteRoleRequest(int roleId)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<RoleReply, GetOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest<RoleRequest>(roleId)
            );
            return binder;
        }

        public static BaseRequestBinder BuildGetRolePermissionRequest(int roleId)
        {
            RolePermissionRequest request = new RolePermissionRequest();
            request.RoleId = roleId;
            request.CommandIdent = CommandIdent.GetRolePermission;

            BaseRequestBinder binder = new TBaseRequestBinder<RolePermissionReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetUserPermissionsRequest(int userId)
        {
            RolePermissionListRequest request = new RolePermissionListRequest();
            request.UserId = userId;
            request.CommandIdent = CommandIdent.GetUserPermissions;

            BaseRequestBinder binder = new TBaseRequestBinder<RolePermissionReply, GetListOperation>
            (
                RequestBuilder.BuildGetEntityListRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildCreateRolePermissionRequest(RolePermission rolePermission)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<RolePermissionReply, AddOperation>
            (
                RequestBuilder.BuildAddEntityRequest<RolePermissionRequest>(rolePermission)
            );
            return binder;
        }
        public static BaseRequestBinder BuildUpdateRolePermissionRequest(RolePermission rolePermission)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<RolePermissionReply, UpdateOperation>
            (
                RequestBuilder.BuildUpdateEntityRequest<RolePermissionRequest>(rolePermission)
            );
            return binder;
        }
        public static BaseRequestBinder BuildDeleteRolePermissionRequest(int rolePermissionId)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<RolePermissionReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest<RolePermissionRequest>(rolePermissionId)
            );
            return binder;
        }

        public static BaseRequestBinder BuildGetUserRequest(int userId)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<UserReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest<UserRequest>(userId)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetUserRequest(Guid memberId)
        {
            UserRequest request = new UserRequest();
            request.CommandIdent = CommandIdent.GetUser;
            request.MemberId = memberId;
            request.EntityId = 0;

            BaseRequestBinder binder = new TBaseRequestBinder<UserReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetUserRequest(UserRequest request)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<UserReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetUserListRequest(UserListRequest request)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<UserReply, GetListOperation>
            (
                RequestBuilder.BuildGetEntityListRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildAddUserRequest(User user)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<UserReply, AddOperation>
            (
                RequestBuilder.BuildAddEntityRequest <UserRequest>(user)
            );
            return binder;
        }
        public static BaseRequestBinder BuildUpdateUserRequest(User user)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<UserReply, UpdateOperation>
            (
                RequestBuilder.BuildUpdateEntityRequest<UserRequest>(user)
            );
            return binder;
        }
        public static BaseRequestBinder BuildDeleteUserRequest(int userId)
        {
            BaseRequestBinder binder = new TBaseRequestBinder<UserReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest<UserRequest>(userId)
            );
            return binder;
        }
    }
}